﻿using UnityEngine;
using UnityEditor;
using AudioStudio;

[CustomPropertyDrawer(typeof(SoundBankParam))]
public class SoundBankParamDrawer : PropertyDrawer
{
    public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
    {
        return label != GUIContent.none && Screen.width < 333 ? (16f + 18f) : 16f;
    }

    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        int oldIndentLevel = EditorGUI.indentLevel;
        label = EditorGUI.BeginProperty(position, label, property);
        Rect contentPosition = EditorGUI.PrefixLabel(position, label);

        if (position.height > 16f)
        {
            position.height = 16f;
            EditorGUI.indentLevel += 1;
            contentPosition = EditorGUI.IndentedRect(position);
            contentPosition.y += 18f;
        }

        EditorGUI.indentLevel = 0;

        float contentWidth = contentPosition.width;

        EditorGUIUtility.labelWidth = 54f;
        contentPosition.width = contentWidth * 0.2f;
        EditorGUI.PropertyField(contentPosition, property.FindPropertyRelative("load"), new GUIContent("Load"));

        contentPosition.x += (contentPosition.width + contentWidth * 0.01f);
        contentPosition.width = contentWidth * 0.2f;
        EditorGUIUtility.labelWidth = 68f;
        EditorGUI.PropertyField(contentPosition, property.FindPropertyRelative("unload"), new GUIContent("Unload"));

        contentPosition.x += (contentPosition.width + contentWidth * 0.01f);
        contentPosition.width = contentWidth * 0.58f;
        EditorGUIUtility.labelWidth = 74f;
        EditorGUI.PropertyField(contentPosition, property.FindPropertyRelative("bank"), new GUIContent("SoundBank"));

        EditorGUI.EndProperty();
        EditorGUI.indentLevel = oldIndentLevel;
    }
}